package day14;

public class sellTicket1 implements Runnable {
    private int Ticket = 100;
    Object obj=new Object();

    //判断票数大于0，就卖票，并告知是哪个窗口卖的 卖了票之后，总票数要减1 票卖没了，线程停止
    @Override
    public void run() {
        while (true) {synchronized (obj){
            if (Ticket <= 0) {
                break;
            } else {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            Ticket--;
            System.out.println(Thread.currentThread().getName()+"正在买票，还剩下"+ Ticket+"张票");
    }}
}
}
